#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(int argc, char** argv) {
    int n,m;
    double a,b,c;
    bool flag;
    cin>>n>>m;
    double all = 0.0;
    double res = 0.0;
    for (int i=0; i<n; ++i) {
        scanf("%lf %d", &a, &flag);
        all += a;
        if (flag) res += a*0.8;
        else res += a;
    }
    for (int i=0; i<m; ++i) {
        scanf("%lf %lf", &b, &c);
        if (b<=all && all-c < res) res = all-c;
    }
    printf("%0.2lf\n", res);
    return 0;
}
